home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
catlog
/
source
/
divide.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
7KB
|
268 lines
/*
NIFTYのLOG整理 divide.c
by GHH01217 山先
$Header: DIVIDE.Cv 1.2 93/02/12 22:46:44 山先 Exp $
*/
#include "log.h"
void check_drive_space_23( )
{
int drive , drive_free;
struct _disk_space info;
if ( output_path[ 1 ] == ':' ) {
drive = toupper( output_path[ 0 ] ) & 0x0f;
} else {
drive = 0; /* カレント drive */
};
info = _dos_get_disk_space( drive );
drive_free = info.nsectors * info.free_clusters * info.nbytes;
/*
printf("%s : %ld\n", output_path , drive_free);
*/
if ( drive_free < 82*310 ) {
printf("\nディスク・スペースが足りません。");
exit( 1 );
};
}
extern int mkdir( const char *path );
/************************************************/
/* output_pathを検査してディレクトリがない場合は作る */
/************************************************/
void check_and_make_output_path( const char *forum_name )
{
int count , sw;
char full[ 128 ],*p1;
strcpy( full , forum_name );
#ifdef TEST
printf("<%s>のディレクトリの有無をチェックします。\n",full);
#endif
count = 0;
p1 = full;
if ( p1[1] == ':' ) p1 += 2;
if ( *p1 == '\\' ) p1++;
while ( *p1 ) {
sw = TRUE;
while ( *p1 != '\\' ) { /* 最初の \ を探す */
if ( *p1 == '\0' ) {
sw = FALSE; break;
};
p1++;
};
if ( sw == FALSE ) break;
*p1 = '\0';
if ( chdir( full ) < 0 ) {
if ( mkdir( full ) != 0 ) {
sprintf(str,"<%s>でディレクトリ<%s>が作れません。",
forum_name,full
);
error_return( str ); return;
};
};
*p1 = '\\'; p1++; count++;
};
strcpy( full , forum_name );
p1 = full;
if ( p1[1] == ':' ) p1 += 2;
*p1 = '\0';
strcat( full , ".." );
while ( count > 0 ) { chdir( full ); count--; };
}
/*****************************/
/* 各ディレクトリの tmp file name */
/*****************************/
static void set_id_tmp_file_name( char *forum , int num , char *collect)
{
char path[ 128 ];
switch( num ) {
case BILL: strcpy( path , "BILL\\" );
strcat( path , BILL_FILE_NAME );
strcat( path , ".tmp" ); break;
case MAIL:
case ALL_MAIL:
if ( MakeUpMAILInto1FileSw == YES ) {
sprintf( path , "NIFMAIL\\catlog%2d.tmp" , MAIL );
} else {
sprintf( path , "NIFMAIL\\%s.tmp" , forum );
};
break;
case CLIP: strcpy( path , "CLIP\\catlog-9.tmp" ); break;
case HP: sprintf( path , "HP\\%s\\%s.tmp",forum,forum); break;
case PATIO: sprintf( path , "PATIO\\%s\\%s.tmp",forum,forum); break;
case LIB: if ( output_DL_List_path[ 0 ] != '\0' ) {
strcpy( file_name , output_DL_List_path );
strcat( file_name , forum );
strcat( file_name , "\\" );
check_and_make_output_path( file_name );
sprintf( path , "catlog%2d.tmp",num);
strcat( file_name , path );
return; /* 終了 */
} else {
sprintf( path , "%s\\catlog%2d.tmp",forum,num);
};
break;
case COLLECT_ID:
sprintf( path , "COLLECT\\%s.tmp" , collect ); break;
case COLLECT_LIB:
if ( output_DL_List_path[ 0 ] != '\0' ) {
strcpy( file_name , output_DL_List_path );
strcat( file_name , "COLLECT\\" );
strcat( file_name , collect );
strcat( file_name , "\\" );
check_and_make_output_path( file_name );
sprintf( path , "catlog%2d.tmp",num);
strcat( file_name , path ); return; /* 終了 */
} else {
sprintf( path , "COLLECT\\%s\\catlog%2d.tmp",
collect,
num
);
};
break;
default: sprintf( path , "%s\\catlog%2d.tmp",forum,num);
file_name_space_0( path ); break;
};
strcpy( file_name , output_path );
strcat( file_name , path );
}
static int divide_loop_check(
char *last_forum , char *forum ,
char *last_collect , char *collect ,
int last_mes_num , int mes_num
) {
if ( *last_forum == '\0' ) return( YES );
if ( mes_num == COLLECT_ID || mes_num == COLLECT_LIB ) {
if ( last_mes_num != mes_num ) return( YES );
if ( strcmp( last_collect , collect ) != 0 ) return( YES );
} else {
if ( last_mes_num == COLLECT_ID || last_mes_num == COLLECT_LIB )
return( YES );
if ( strcmp( last_forum , forum ) != 0 ) return( YES );
if ( last_mes_num != mes_num ) return( YES );
};
return( NO );
}
/*******************************/
/* 発言毎にディレクトリに切り分ける */
/*******************************/
/*
CATLOG.TMP には、次の順番に標準のデータが登録されている
CATLOG.TMP の発言の区切り
フォーラム名
会議室番号
発言番号
発言の日付
コメント先番号
発言者のID
forum_name_line[ 80 ];
forum_sub_name_line[ 80 ];
*/
static void divide_loop( )
{
int sw , mes_num , last_mes_num;
char forum[ 12 ],collect[ 12 ];
char last_forum[ 12 ],last_collect[ 12 ];
GET_LINE; /* *****log整理 */
*last_forum = *last_collect = '\0';
last_mes_num = mes_num = 0;
sw = FALSE;
forever {
check_pool_delete_start = PresentStrPtr;
GET_LINE; /* Forum名 or ID名 */
/* 以下は実行しないはずなのだが……… */
if ( PresentStrLen < 1 || 8 < PresentStrLen ) {
present_str_print();
strcpy(str,"divideでおかしな行 ↑ をみつけました。FORUM名");
error_bug( str );
};
present_str_copy( forum );
GET_LINE; /* 会議室番号 */
/* 以下は実行しないはずなのだが……… */
if ( PresentStrLen > 2 ) {
present_str_print();
strcpy(str,"divideでおかしな行 ↑ をみつけました。MES_NUM\n");
error_bug( str );
};
mes_num = atoi( PresentStrPtr );
GET_LINE; /* 発言番号 */
hatsugen_number = atoi( PresentStrPtr );
GET_LINE; /* 発言の日付 */
GET_LINE; /* コメント先番号 */
GET_LINE; /* 発言者のID */
if ( PresentStrLen != 0 ) { /* IDによる収集の発言である */
present_str_copy( collect );
} else {
*collect = '\0';
};
/*
Collect_ID or Collect_ID_LIB の場合、collect の一致
その他の場合、forum , mes_num の一致
*/
if ( divide_loop_check(
last_forum , forum ,
last_collect , collect ,
last_mes_num , mes_num
) == YES
) {
if ( *last_forum != '\0' ) fclose( catlog_fpo );
/* open out put file */
set_id_tmp_file_name( forum , mes_num , collect );
check_and_make_output_path( file_name );
if ( (catlog_fpo=fopen( file_name , "ab" ))==NULL ) {
error_open_file( "divide_loop" ); error_end();
};
strcpy( last_forum , forum );
last_mes_num = mes_num;
strcpy( last_collect , collect );
};
GET_LINE2 break;
while ( strncmp( PresentStrPtr , "*****log整理" , 12 ) != 0 ) {
GET_LINE2 { sw = TRUE; break; };
};
/* disk full のテストを行う */
check_drive_space_23( );
if ( catlog_fwrite( ) == 0 ) {
sprintf(str,"divide_loop 書き込みが出来ませんでした");
error_return( str ); break;
};
if ( sw == TRUE ) break;
};
fclose( catlog_fpo );
}
void divide_main()
{
size_t fsize;
set_tmp0_file_name( file_name );
if ( (fsize = _get_file_size( file_name ) ) > 100 ) {
initial_check_pool( fsize , NO );
divide_loop( );
end_check_pool();
};
/* 最後に巨大なファイルの削除を行う */
delete_tmp0_file();
}